﻿using CommonPatterns.MVVM;
using OCDP.Client.Adapters;
using OCDP.Client.Model;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;

namespace OCDP.Client.Screens.ToolBox
{
    public class ToolBoxViewModel : ViewModelBase, IToolBoxViewModel
    {
        #region Fields
        public ObservableCollection<OperatorAdapter> Operators { get; set; }
        #endregion

        #region Constructor
        public ToolBoxViewModel()
        {
            string operatorsStr = @"Scan Cvs|/OCDP.Client;component/Resources/Icones/Scan.gif|
                                 Scan Table|/OCDP.Client;component/Resources/Icones/Scan.gif|
                                 Selection|/OCDP.Client;component/Resources/Icones/Select.gif|
                                 Projection|/OCDP.Client;component/Resources/Icones/EvalFas.gif|
                                 Nest|/OCDP.Client;component/Resources/Icones/Nest.gif|
                                 Cartesian Product|/OCDP.Client;component/Resources/Icones/CartProd.gif|
                                 Union|/OCDP.Client;component/Resources/Icones/Union.gif";

            Title = "Binded ToolBoxViewModel !!";
            Operators = GetOperatorAdapters(operatorsStr);
        }
        #endregion

        #region Helpers
        private ObservableCollection<OperatorAdapter> GetOperatorAdapters(string operatorsStr)
        {
            var operators = new ObservableCollection<OperatorAdapter>();
            string[] operatorsElement = operatorsStr.Split('|');
            for (int i = 0; i < operatorsElement.Length; i = i+2)
            {
                var operator_ = new Operator() 
                { 
                    OperatorName = operatorsElement[i].Trim(),
                    IconRessourcePath = operatorsElement[i + 1].Trim()
                };
                operators.Add(new OperatorAdapter(operator_));
            }
            return operators;
        }
        #endregion
    }
}
